package com.huixuebao.settle.controller;

import cn.hutool.core.util.ObjectUtil;
import com.huixuebao.common.bean.ApiResult;
import com.huixuebao.settle.dto.UserDTO;
import com.huixuebao.settle.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * TODO
 *
 * @version 1.0
 * @date 2020-11-11 22:30
 */
@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserService userService;

    @GetMapping("/info")
    public ApiResult<UserDTO> getUserByPhone(@RequestParam("phone") String phone) {
        ApiResult<UserDTO> apiResult = new ApiResult<>();
        UserDTO userDTO = userService.getUserByPhone(phone);
        if (ObjectUtil.isNotNull(userDTO)) {
            apiResult.setData(userDTO);
            return apiResult;
        } else {
            apiResult.setSuccess(false);
            return apiResult;
        }
    }

}